import Express from "express";
import { addArtServ, delArtServ, findArtByPageServ, updateArtServ, findArtByIdServ} from "../Service/artService.js";

export const articlesRouter = Express.Router()

articlesRouter.post("/",async(req,res)=>{
    const data = await addArtServ(req.body);
    res.json(data)
})

articlesRouter.delete("/:id",async(req,res)=>{
    const data = await delArtServ(req.params.id)
    res.json(data)
})

articlesRouter.put("/:id",async(req,res)=>{
    const data = await updateArtServ(req.params.id,req.body);
})

articlesRouter.get("/",async(req,res)=>{
    const {page,size,searchValue,type} = req.query;
    const queryobj = {
        
    };
    if(searchValue){
        queryobj.title = searchValue;
    }
    if(type){
        queryobj.typeId = type;
    }
    const result = await findArtByPageServ(page,size,queryobj)
    res.json(result);
})
articlesRouter.get("/:id",async(req,res)=>{
    
    
    const result = await findArtByIdServ(req.params.id)
    res.json(result)
})
